﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Security.Cryptography;
using System.IO;
using System.Text;

using CE.Image;
using CE.User;
using CE.Mail;
using CE.Global;

public partial class user_FeedBack : System.Web.UI.Page
{
    protected override void InitializeCulture()
    {
        String selectedCulture = CE.Global.General.SetCulture();
        base.InitializeCulture();
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session[CE.Global.General.UserId] == null)
        {
            Response.Redirect("~/SiteUserSecureLogin.aspx");
        }
        if (!Page.IsPostBack)
        {
            txtName.Text = Session[CE.Global.General.UserName].ToString();
            txtEmail.Text = Session[CE.Global.General.UserEmail].ToString();
            txtFeedBack.Text = "";
            txtEmotionType.Text = "";
            txtFeedbackType.Text = ""; 
        }
    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            string strMessage = "";
            strMessage += "<br/>Sender : " + Server.HtmlEncode(CE.Global.General.ClearScriptTag(txtName.Text)) + "<br /><br />";
            strMessage += "Email : " + txtEmail.Text + "<br /><br />";
            strMessage += "What you feel?  : " + GetFeedback() + "<br /><br />";
            strMessage += "Feedback Type  : " + GetEmotion() + "<br /><br />";
            strMessage += "Message : <br/>" + Server.HtmlEncode(CE.Global.General.ClearScriptTag(txtFeedBack.Text.Replace("\n\r","<br />"))) + "<br />";

            string _emailTitle = "GG CRM Feedback (" + txtName.Text + ") @ " + CE.Global.General.GetUTCDateTime().ToString("dd/MMM/yyyy hh:mm tt");
            string _toemail = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Feedback_TO");
            string _ccemail = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Feedback_CC");
            string _bccemail = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Feedback_BCC");
            if (MyMailManager.SendGGMail(ConfigurationManager.AppSettings["GGFormsSMTPAccount"].ToString(), ConfigurationManager.AppSettings["GGFormsSMTPAuthCode"].ToString(), _toemail, _ccemail, _bccemail, _emailTitle, strMessage, Session[General.SMTPReplyTo].ToString()))
            {
                divThankYou.Visible = true;
                txtFeedBack.Enabled = true;
                btnSubmit.Enabled = false;
            }
            else
            {
            }
        }
    }

    private Int16 GetFeedbackType()
    {
        Int16 _result = 0;
        if (txtFeedbackType.Text == "0")
        {
            _result = 1;
        }
        else
        {
            _result = Convert.ToInt16(txtFeedbackType.Text);
        }
        return _result;
    }

    private string GetFeedback()
    {
        string _result = "";
        if (txtFeedbackType.Text == "1")
        {
            _result = "Suggestion";
        }
        else if (txtFeedbackType.Text == "2")
        {
            _result = "Compliment";
        }
        else if (txtFeedbackType.Text == "3")
        {
            _result = "Bug Report";
        }
        return _result;
    }

    private string GetEmotion()
    {
        string _result = "";
        if (txtEmotionType.Text == "1")
        {
            _result = "Very Useful";
        }
        else if (txtEmotionType.Text == "2")
        {
            _result = "Good";
        }
        else if (txtEmotionType.Text == "3")
        {
            _result = "OK";
        }
        else if (txtEmotionType.Text == "4")
        {
            _result = "Sad";
        }
        else if (txtEmotionType.Text == "5")
        {
            _result = "Angry";
        }
        return _result;
    }

}